<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>对象</title>
</head>

<body>
    <script>
        //对象与java相似，都可拥有属性和方法，但js中常常只拥有属性
        //创建方式
        //第一种{}
        let obj = {
            name: "White",
            age: "20"
        }
        obj.sayHello = function sayHello(a){
            console.log(a)
        }
        obj.sayHello("你好")
        console.log(obj)
        console.log(obj.name)
        console.log(obj['age'])

        //第二种 new
        let obj1 = new Object()
        obj1.name = 'Black'
        obj1.age = 18
        obj1.height = 180
        console.log(obj1.name)

        //第三种 构造函数
        function Person(name,price,time,id){
            this.name = name
            this.price = price
            this.time = time
            this.id = id
            this.sayHi = a =>{
                console.log(a)
            }
        }
        let obj2 = new Person("红楼梦",23,"9月26日","000001")
        console.log(obj2)
        console.log(obj2.time + "编号序列为" + obj2.id + "的书" + obj2.name + "被借出，逾期赔偿" + obj2.price + "元")
        obj2.sayHi("再见")

        function Sum(num1,num2,num3){
            this.num1 = num1
            this.num2 = num2
            this.num3 = num3
            this.sum = res => {
                let result = num2 ** 2 - 4 * num1 * num3
                console.log(result)
            }
        }
        let su = new Sum(3,4,5)
        console.log(su.sum())
        


    </script>
</body>

</html>